<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="标准号" prop="standardName">
        <el-input
          v-model="queryParams.standardCode"
          placeholder="请输入标准号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="序号" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入序号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="评价名称" prop="evaluationName">
        <el-input
          v-model="queryParams.evaluationName"
          placeholder="请输入评价名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="指标体系" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入指标体系"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="备注" prop="dictType">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.dictType"-->
      <!--          placeholder="请输入备注"-->
      <!--          clearable-->
      <!--          style="width: 240px"-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->

      <!--暂时删除状态-->

      <!-- el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="状态"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item -->

      <!--      <el-form-item label="创建时间">-->
      <!--        <el-date-picker-->
      <!--          v-model="dateRange"-->
      <!--          style="width: 240px"-->
      <!--          value-format="yyyy-MM-dd"-->
      <!--          type="daterange"-->
      <!--          range-separator="-"-->
      <!--          start-placeholder="开始日期"-->
      <!--          end-placeholder="结束日期"-->
      <!--        ></el-date-picker>-->
      <!--      </el-form-item>-->
      <el-form-item label="评估时间"prop="startDate">
        <el-date-picker
          v-model="queryParams.startDate"
          type="date"
          placeholder="开始日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="" prop="endDate">
        <el-date-picker
          v-model="queryParams.endDate"
          type="date"
          placeholder="结束日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" v-hasPermi="['system:result:search']">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--创建时间和下面列表之间的新增，修改，删除，导出，刷新缓存，注释掉，2024/7/19-->
    <!--el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:dict:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:dict:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:dict:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:dict:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshCache"
          v-hasPermi="['system:dict:remove']"
        >刷新缓存</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row-->

    <el-table v-loading="loading" :data="dataList"  :default-sort="{prop:'evaluateDate',order:'descending'}" @sort-change="handleSortChange">
      <!--el-table-column type="selection" width="55" align="center" /-->
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="评价名称" align="center" prop="evaluationName" :show-overflow-tooltip="true" />
      <el-table-column label="标准号" align="center" prop="standardCode" :show-overflow-tooltip="true" />
      <el-table-column label="标准名称" align="center" prop="standardName" :show-overflow-tooltip="true" />
      <el-table-column label="指标体系" align="center" prop="projectName" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="总评结果" align="center" prop="outputValue" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="公开状态" align="center" prop="publicStatus">
        <template slot-scope="scope">
          <el-tag :type="getStatusTagType(getStatusTagMean(scope.row.publicStatus))">
            {{ getStatusTagMean(scope.row.publicStatus) }}
          </el-tag>
        </template>
      </el-table-column>
      <!--暂时删除备注over-->
      <!--el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" /-->
      <el-table-column label="评估时间" align="center" prop="evaluateDate" width="180" :sort-orders="['descending','ascending']" sortable="custom">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.evaluateDate) }}</span>
          <!--          <span>{{ new Date().toLocaleString() }}</span>-->
        </template>
      </el-table-column>
      <el-table-column label="数据分析" align="center" class-name="small-padding fixed-width">
        <<template slot-scope="scope">
        <!--注释掉 修改、删除 两部分-->
        <el-button
          size="mini"
          type="text"
          icon="el-icon-s-order"
          @click="handleScore(scope.row)"
          v-hasPermi="['system:result:detailed']"
        >指标得分</el-button>
        <el-button
          size="mini"
          type="text"
          icon="el-icon-s-marketing"
          @click="handlePath(scope.row)"
          v-hasPermi="['system:result:trend']"
        >影响力变化历史</el-button>
        <el-button
          size="mini"
          type="text"
          icon="el-icon-magic-stick"
          @click="handleVisualization(scope.row)"
          v-hasPermi="['system:result:IndicatorEvaluationScore']"
        >可视化</el-button>
      </template>el-table-column label="编辑设置" align="center" class-name="small-padding fixed-width">
      </el-table-column>
      <el-table-column label="编辑设置" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!--注释掉 修改、删除 两部分-->

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:result:edit']"
          >修改评价名称</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-open"
            @click="handleUpdateIsPublic(scope.row)"
            v-hasPermi="['system:result:alterpublic']"
          >设置公开</el-button>
          <!--el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:dict:remove']"
          >删除</el-button-->
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="isAddDialogOpen" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="评价名称" prop="evaluationName">
          <el-input v-model="form.evaluationName" placeholder="请输入评价名称" />
        </el-form-item>
        <!--el-form-item label="标准名称" prop="standardName">
          <el-input v-model="form.standardName" placeholder="请输入标准名称" />
        </1el-form-item-->
        <!--el-form-item label="选择数据类型" prop="status"-->
        <!--el-select
          v-model="queryParams.status"
          placeholder="数据类型"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
              <el-form-item label="选择评估方式" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="评估方式"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item-->

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitNameChange">确 定</el-button>
        <el-button @click="cancelUpdateName">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="isAlterPublic" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公开状态" prop="publicStatus">
          <el-select v-model="form.publicStatus" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPublicChange">确 定</el-button>
        <el-button @click="cancelAlterIsPublic">取 消</el-button>
      </div>
    </el-dialog>
    <!--指标得分对话框-->
    <!--    <el-dialog :title="title" :visible.sync="isScoreDialogOpen" width="500px" append-to-body>-->
    <!--      <el-table v-loading="loading" :data="dataList2" @selection-change="handleSelectionChange">-->
    <!--        <el-table-column label="指标名称" align="center" prop="standardName" />-->
    <!--        <el-table-column label="指标介绍" align="center" prop="introduction" :show-overflow-tooltip="true" />-->
    <!--        <el-table-column label="得分" align="center" prop="accessResult":show-overflow-tooltip="true"></el-table-column>-->
    <!--      </el-table>-->
    <!--    </el-dialog>-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getResultList"
    />
  </div>
</template>

<script>
import { listMenu, getMenu, delMenu, addMenu, updateMenu } from "@/api/system/menu";
import {listResultMethod , searchResultMethod , getEvaluateName , updateEvaluateName , alterEvaluateIsPublic} from "@/api/evaluate/evaluateResult"
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import IconSelect from "@/components/IconSelect";

export default {
  name: "result/list",
  data() {
    return {
      total:0,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      isScoreDialogOpen:false,
      dataList:[],
      options: [
        { value: 1, label: '公开' },
        { value: 0, label: '暂不公开' },
      ],
      //搜索的状态下拉框
      statusOptions : [
        {
          value: '1',
          label: '审核通过',
        },
        {
          value: '0',
          label: '审核失败',
        },
        {
          value: '-1',
          label: '待审核',
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开，默认全部折叠
      isExpandAll: false,
      // 新增对话框显示状态，默认为false
      isAddDialogOpen: false,
      // 修改对话框显示状态，默认为false
      isUpdateDialogOpen: false,
      //修改公开状态的对话框
      isAlterPublic:false,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        id:undefined,
        standardName:undefined,
        projectName:undefined,
        standardCode:undefined,
        evaluationName: undefined,
        startDate:undefined,
        endDate:undefined,
        visible: undefined,
        pageNum:1,
        pageSize:10,
        orderByColumn: undefined,
        isAsc:undefined,
      },
      pageParams:{
        orderByColumn: undefined,
        isAsc:undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
    };
  },
  created() {
    this.getResultList();
  },
  beforeMount() {
    this.handleSortChange(
      {
        prop:'evaluateDate',
        order:'descending'
      }
    );
  },
  methods: {
    // 选择图标
    getResultList()
    {
      this.loading=true;
      listResultMethod(this.queryParams).then(response => {
        this.dataList=response.rows;
        console.log(this.dataList);
        this.loading=false;
        this.total=response.total;
      });
    },

    searchResultList()
    {
      this.loading=true;
      searchResultMethod(this.queryParams).then(response=>
      {
        this.dataList=response.rows;
        this.total = response.total;
        this.loading=false;
      })
    },
    selected(name) {
      this.form.icon = name;
    },

    /** 获取状态 */
    getStatusTagType(status) {
      if (status === '公开') {
        return 'success';
      } else if (status === '暂未公开') {
        return 'warning';
      } else if (status === '已公开') {
        return 'success';
      } else {
        return 'info';
      }
    },
    getStatusTagMean(statusId)
    {
      if(statusId===1)
      {
        return "已公开";
      }else if(statusId ===0)
      {
        return"暂未公开";
      }else
      {
        return"暂未公开";
      }
    },

    /** 查询菜单列表 */
    getList() {
      this.loading = true;
      listMenu(this.queryParams).then(response => {
        this.menuList = this.handleTree(response.data, "menuId");
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open= false;
      this.reset();
    },
    cancelUpdateName(){
      this.isAddDialogOpen=false;
      this.reset();
    },
    cancelAlterIsPublic()
    {
      this.isAlterPublic=false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        menuId: undefined,
        parentId: 0,
        menuName: undefined,
        icon: undefined,
        menuType: "M",
        orderNum: undefined,
        isFrame: "1",
        isCache: "0",
        visible: "0",
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum=1;
      this.searchResultList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      getEvaluateName(row.id).then(response => {
        this.form = response.data;
        this.isAddDialogOpen = true;
        this.title = "修改评价名称";
      });
    },
    handleUpdateIsPublic(row) {
      this.reset();
      getEvaluateName(row.id).then(response => {
        this.form = response.data;
        this.isAlterPublic = true;
        this.title = "公开评价结果";
      });
    },
    /** 指标得分按钮操作 */
    handleScore(row){
      // console.log('row:', row);
      this.$store.commit('evaluate/SET_EVALUATION_ID', row.id);
      this.$router.push('/access/result/score');
    },
    handlePath(row){
      this.$store.commit('evaluate/SET_STANDARD_ID', row.standardCode);
      console.log('standardCode ID:', row.standardCode);
      this.$router.push('/access/result/path')
    },
    handleVisualization(row){
      this.$store.commit('evaluate/SET_EVALUATION_ID', row.id);
      this.$router.push('/access/result/visualization')
    },
    /** 提交按钮 */
    submitNameChange: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateEvaluateName(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.isAddDialogOpen = false;
              // this.getList();
              this.getResultList();
            });
          }
          this.isAlterPublic=false;
        }
      });
    },
    submitPublicChange: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            alterEvaluateIsPublic(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.isAddDialogOpen = false;
              // this.getList();
              this.getResultList();
            });
          }
        }
        this.isAlterPublic=false;
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除名称为"' + row.menuName + '"的数据项？').then(function() {
        return delMenu(row.menuId);
      }).then(() => {
        // this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    handleSortChange(column) {
      this.queryParams.orderByColumn = column.prop;//查询字段是表格中字段名字
      this.queryParams.isAsc = column.order;//动态取值排序顺序
      this.getResultList();
    }
  }
};
</script>

<style scoped>

</style>
